#include"dma.h"

void dma_init(void)
{
    //时钟
    RCC->AHBENR|=RCC_AHBENR_DMA1EN;

    DMA1_Channel4->CCR|=DMA_CCR4_DIR;//从存储器读

    DMA1_Channel4->CCR&=~DMA_CCR4_MSIZE;//字节大小
    DMA1_Channel4->CCR&=~DMA_CCR4_PSIZE;

    DMA1_Channel4->CCR|=DMA_CCR4_MINC;  //存储器地址自增
    DMA1_Channel4->CCR&=~DMA_CCR4_PINC; //外设usart的DR寄存器地址是固定的，不自增。

    USART1->CR3|=USART_CR3_DMAT;
    
}

void dma_usart(uint32_t scr,uint32_t des,uint32_t leng)
{
    DMA1_Channel4->CMAR=scr;
    DMA1_Channel4->CPAR=des;

    DMA1_Channel4->CNDTR=leng;
    DMA1_Channel4->CCR|=DMA_CCR4_EN;
}


